package org.example.GC;

public class MyCircularQueue {
    private int[] nums;
    private int size;
    private int front=0;
    private int rear=0;

    public MyCircularQueue(int k) {
        this.size = k;
        nums = new int[size+1];
    }

    public boolean enQueue(int value) {
        if (isFull()) {
            return false;
        } else {
            rear = (rear + 1) % nums.length;
            nums[rear] = value;
            return true;
        }
    }

    public boolean deQueue() {
        if (isEmpty()) {
            return false;
        } else {
            front = (front + 1) % nums.length;
            return true;
        }
    }


    public int Front() {
        if (isEmpty()) {
            return -1;
        } else {
            int temp=(front+1)%nums.length;
            return nums[temp];
        }
    }

    public int Rear() {
        if (isEmpty()) {
            return -1;
        } else {
            return nums[rear];
        }
    }

    public boolean isEmpty() {
        return rear == front;

    }

    public boolean isFull() {
        return (rear + 1) % nums.length == front;
    }
}